<template>
  <div class="zuo">
    <div class="user-info">
      <img :src="driverInfo.photo" alt="" class="user-avatar" style="width: 50px;height: 50px;border-radius: 50%"/>
      <p class="user-name">{{ driverInfo.name }}</p>
    </div>
    <div class="asset-summary">
      <p>资产总额(元)：<span class="total-assets">{{ this.sumpricefund }}</span>
<!--        <van-button @click="towithdrawdeposit()" class="total-tixian" type="primary" size="small" round>提现-->
<!--        </van-button>-->
      </p>
      <p>当月收入(元)：<span>{{ monthmoney }}</span></p>
      <p @click="monthGet()">当月提现(元)：<span>{{ dangyuemoney }}</span></p>
    </div>
    <div class="settings-options">
      <van-grid :column-num="3">
        <van-grid-item icon="star-o" text="常用地址" @click="NotOpened()"></van-grid-item>
        <van-grid-item icon="comment-circle" text="设置密码" @click="NotOpened()"></van-grid-item>
        <van-grid-item icon="graphic" text="修改手机号" @click="NotOpened()"></van-grid-item>
      </van-grid>
      <van-cell title="运营统计" @click="tongji()" is-link icon="column"></van-cell>
      <van-cell title="用户指南" is-link icon="label" @click="zhinan()"></van-cell>
      <van-cell title="设置" @click="shezhi()" is-link icon="setting"></van-cell>
      <van-cell title="关于" @click="guanyu()" is-link icon="point-gift"></van-cell>
      <van-cell title="添加车辆信息" @click="savecar()" is-link icon="logistics"></van-cell>
    </div>
    <van-tabbar route>
      <van-tabbar-item icon="home-o" to="/shouye">首页</van-tabbar-item>
      <van-tabbar-item icon="reorder-o" @click="toDingdan" to="/orders">订单</van-tabbar-item>
      <van-tabbar-item icon="wallet-o" @click="toqianbao">钱包</van-tabbar-item>
      <van-tabbar-item icon="chat-o" @click="toxiaoxi">消息</van-tabbar-item>
      <van-tabbar-item icon="my-o" @click="toPersonalCenter" to="/my">我的</van-tabbar-item>
    </van-tabbar>
  </div>
</template>
<script>
import axios from "axios";

export default {
  data() {
    return {
      driverInfo: {},
      id: '',
      form: {},
      summoney: "",
      sumpricefund: "",
      monthmoney: "",
      value1: '',
      dangyuemoney: "",
      summoney2: "",
      sumprice: "",
    };
  },
  methods: {
    async savecar() {
      try {
        await this.$router.push({path: '/saveCar'});
      } catch (error) {
        console.error("导航到添加车辆信息页面失败:", error);
      }
    },
    async pric() {
      axios.get(`order/driver/sjById?id=${this.useId}`).then(res => {
        this.sumpricefund = res.data.totalAssets;
        // sessionStorage.setItem("sumpricefund", JSON.stringify(res.data.totalAssets));
      })
    },
    async dangyuetixian() {
      axios.post(`personal/personal/dangyuetixian?driverId=${this.driverInfo.id}`).then(res => {
        this.dangyuemoney = res.data;
      })
    },
    async dangyueshouru() {
      try {
        const response = await axios.post(`personal/personal/dangyueshouru?did=${this.driverInfo.id}`);
        this.monthmoney = response.data;
      } catch (error) {
        console.error("获取当月收入失败:", error);
      }
    },
    async zichanzonge() {
      try {
        const response = await axios.post(`personal/personal/zichanzonge?did=${this.driverInfo.id}`);
        sessionStorage.setItem('useId', this.driverInfo.id)
        this.summoney = response.data;
        sessionStorage.setItem('summoney', this.summoney);
        console.log("总金额：========" + this.summoney)
      } catch (error) {
        console.error("获取资产总额失败:", error);
      }
    },
    async findDriverByTel() {
      try {
        const tel = JSON.parse(localStorage.getItem('login'));
        const response = await axios.post('personal/personal/findByTel?tel=' + tel);
        this.driverInfo = response.data;
      } catch (error) {
        console.error("根据手机号查找司机信息失败:", error);
      }
    },
    async monthGet() {
      try {
        await this.$router.push({path: '/WithdrawRecord'});
      } catch (error) {
        console.error("导航到当月提现记录页面失败:", error);
      }
    },
    async towithdrawdeposit() {
      try {
        await this.$router.push({path: '/WithdrawDeposit'});
      } catch (error) {
        console.error("导航到提现页面失败:", error);
      }
    },
    async toPersonalCenter() {
      try {
        await this.$router.push({path: '/PersonalCenter'});
      } catch (error) {
        console.error("导航到个人中心页面失败:", error);
      }
    },
    async toxiaoxi() {
      try {
        await this.$router.push({path: '/newIndex'});
      } catch (error) {
        console.error("导航到消息页面失败:", error);
      }
    },
    async toDingdan() {
      try {
        await this.$router.push("/dcOrders");
      } catch (error) {
        console.error("导航到订单页面失败:", error);
      }
    },
    async tongji() {
      try {
        await this.$router.push({path: '/Statistics'});
      } catch (error) {
        console.error("导航到运营统计页面失败:", error);
      }
    },
    async guanyu() {
      try {
        await this.$router.push({path: '/About'});
      } catch (error) {
        console.error("导航到关于页面失败:", error);
      }
    },
    async zhinan() {
      try {
        await this.$router.push({path: '/UserGuide'});
      } catch (error) {
        console.error("导航到用户指南页面失败:", error);
      }
    },
    async shezhi() {
      try {
        await this.$router.push({path: '/SetUp'});
      } catch (error) {
        console.error("导航到设置页面失败:", error);
      }
    },
    async toqianbao() {
      try {
        await this.$router.push('/card');
      } catch (error) {
        console.error("导航到钱包页面失败:", error);
      }
    },
    NotOpened() {
      this.$toast.fail('该功能暂未开放');
    },
    toshouye() {
      this.$router.push("/shouye");
    },
  },
  async created() {
    this.sumpricefund = sessionStorage.getItem("sumpricefund")
    await this.findDriverByTel();
    this.id = this.$route.params.id;
    this.value1 = sessionStorage.getItem("value1")
    this.summoney2 = sessionStorage.getItem("summoney2")
    this.sumprice = sessionStorage.getItem("sumprice")
    await this.zichanzonge();
    await this.dangyueshouru();
    await this.dangyuetixian();
    this.useId = sessionStorage.getItem("useId")
    await this.pric()
  },
};
</script>

<style scoped>
.zuo {
  text-align: left;
  margin-left: 30px;
  width: 350px;
  margin-top: 60px;
}

.user-info {
  display: flex;
  align-items: center;
}

.avatar {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  margin-right: 10px;
}

.name-level {
  line-height: 1.5;
}

.asset-summary {
  margin-top: 30px;
  padding-left: 50px;
  border: #2c3e50 solid 2px;
  border-radius: 10px;
  background-color: #f5f5f5;
  width: 300px;
  height: 170px;
}

.settings-options {
  margin-top: 20px;
  width: 355px;
}

.total-assets {
  color: #070e15;
  font-size: 25px;

}

.total-tixian {
  left: 20px;
  background-color: orange;
  width: 100px;
  font-size: 20px;
  color: white;
}
</style>
